{extend name="public:base" /}
{block name="theme"}管理员管理{/block}
{block name="small_theme"}权限列表{/block}
{block name="breadcrumb"}
<li><a href="{:url('role_group')}">权限列表</a></li>
<li class="active">权限 </li>
{/block}
{block name="content"}
<link rel="stylesheet" href="__CSS__/indexcommon.css">
<div class="row" style="padding:15px;">
    <div class="col-xs-12 table-responsive">
        <div class="box box-list">
            <div class="box-header" data-original-title="" style="height: 40px;">
                <a href="{:url('add_role')}" class="btn"><h2 style="margin-top: 0;"><i class="glyphicon glyphicon-plus"></i> 添加用户组</h2></a>
                <!--<button type="button" class="btn" id="abtn" style="border:none;outline: none;box-shadow: none;"><h2 style="margin-top: 0"><i class="glyphicon glyphicon-tags"></i> 显示选项</h2></button>-->
            </div>
            <!-- /.box-header -->
            <form class="ajaxForm2" method="post" action="{:url('role_group_runaccess')}">
            <!--<div class="box-body table-responsive no-padding" style="border-bottom: 1px solid #dfdfdf;overflow: hidden;">-->
                <table border="0" align="center" cellpadding="0" cellspacing="0" class="table table-striped table-hover table-condensed">
                    <tr>
                        <td height="30" style="border-bottom:#CCCCCC solid 1px; line-height:25px;">配置规则:<br />
                            1、由于页面原因，权限分配为四级，同时控制左侧导航以及用户权限<br />
                            2、部分不需要分配的权限需要在Menu的控制器里手动添加<br />
                        </td>
                    </tr>
                    <tr>
                        <td height="30" style="padding-left:10px;border-bottom:#CCCCCC solid 1px; line-height:25px; background-color:#F4F8FB" class="icheck">
                            <label class="pos-rel">
                                <input type="checkbox" class=""  id='chkAll' onclick='CheckAll(this.form)' value="全选"/>
                                <span class="lbl"> 权限全选</span>
                            </label>
                        </td>
                    </tr>
                    {foreach name="datab" item="vo"}
                    <tr>
                        <td height="40" style="border-bottom:#CCCCCC solid 1px;padding-left:10px;background-color: #ebebeb;">
                            <label>
                                <input {in name="vo.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent" type="checkbox"  value="{$vo.id}" dataid="id-{$vo['id']}" /><span class="lbl"> <strong>{$vo.title}</strong></span>
                            </label>
                        </td>
                    </tr>
                    {foreach name="vo['sub']" item="sub"}
                    <tr>
                        <td height="30" style="padding-left:30px;border-bottom:#E7EBF8 dashed 1px; color:#333333">
                            <label>
                                <input {in name="sub.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" id="{$sub.id}" class="ace ace-checkbox-2 checkbox-parent checkbox-child" type="checkbox"  value="{$sub.id}" dataid="id-{$vo['id']}-{$sub['id']}" /><span class="lbl"> {$sub.title}</span>
                            </label>
                        </td>
                    </tr>
                    {foreach name="sub['sub']" item="subb"}
                    <tr>
                        <td height="30" style="padding-left:50px;border-bottom:#E7EBF8 dashed 1px; color:#666666">
                            <label class="thopen">
                                <input {in name="subb.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" class="ace ace-checkbox-2 checkbox-parent checkbox-child" type="checkbox"  id="{$subb.id}" value="{$subb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}" />
                                <span class="lbl" style="margin-right:20px;"> {$subb.title}</span>
                            </label>
                        </td>
                    </tr>
                    {if condition="!empty($subb['sub'])"}
                    <tr>
                        <td height="30" style="padding-left:70px;border-bottom:#E7EBF8 dashed 1px; color:#666666">
                            {volist name="subb['sub']" id="subbb"}
                            <label class="thopen">
                                <input {in name="subbb.id" value="$admin_group['rules']"}checked{/in} name="new_rules[]" class="ace ace-checkbox-2 checkbox-child" type="checkbox"  id="{$subbb.id}" value="{$subbb.id}" dataid="id-{$vo['id']}-{$sub['id']}-{$subb['id']}-{$subbb['id']}" />
                                <span class="lbl" style="margin-right:20px;"> {$subbb.title}</span>
                            </label>
                            {/volist}
                        </td>
                    </tr>
                    {/if}
                    {/foreach}
                    {/foreach}
                    {/foreach}
                </table>
            <!--</div>-->
            <div class="btn-box">
                <input type="hidden" value="{$admin_group.id}" name="id">
                <button type="submit" class="btn btn-color-o" id="submit">确定</button>
                <button type="reset" class="btn btn-color-b">返回</button>
            </div>
            </form>
            <!-- /.box-body -->
            <!--<ul class="pagination pagination-centered pagination-list">-->
                <!--<li><a href="#">上一页</a></li>-->
                <!--<li class="active">-->
                    <!--<a href="#">1</a>-->
                <!--</li>-->
                <!--<li><a href="#">2</a></li>-->
                <!--<li><a href="#">3</a></li>-->
                <!--<li><a href="#">4</a></li>-->
                <!--<li><a href="#">下一页</a></li>-->
            <!--</ul>-->
        </div>
        <!-- /.box -->
    </div>
</div>
{/block}
{block name="js"}
<script>
    /* 权限配置 */
    $(function () {
        //动态选择框，上下级选中状态变化
        $('input.checkbox-parent').on('change', function () {
            var dataid = $(this).attr("dataid");
            $('input[dataid^=' + dataid + '-]').prop('checked', $(this).is(':checked'));
        });
        $('input.checkbox-child').on('change', function () {
            var dataid = $(this).attr("dataid");
            dataid = dataid.substring(0, dataid.lastIndexOf("-"));
            var parent = $('input[dataid=' + dataid + ']');
            if ($(this).is(':checked')) {
                parent.prop('checked', true);
                //循环到顶级
                while (dataid.lastIndexOf("-") != 2) {
                    dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                    parent = $('input[dataid=' + dataid + ']');
                    parent.prop('checked', true);
                }
            } else {
                //父级
                if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                    parent.prop('checked', false);
                    //循环到顶级
                    while (dataid.lastIndexOf("-") != 2) {
                        dataid = dataid.substring(0, dataid.lastIndexOf("-"));
                        parent = $('input[dataid=' + dataid + ']');
                        if ($('input[dataid^=' + dataid + '-]:checked').length == 0) {
                            parent.prop('checked', false);
                        }
                    }
                }
            }
        });
    });
</script>
<script type="text/javascript">
    highlight_subnav("{:url('role_group')}");
    /* 通用表单不带检查操作，失败跳转 */
    $(function () {
        $('.ajaxForm2').ajaxForm({
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });
    });

</script>
{/block}